
const Utils = {
    generateCurl(method, url, data, headers) {
        let curlParts = ['curl'];

        if (method.toUpperCase() !== 'GET') {
            curlParts.push(`-X ${method.toUpperCase()}`);
        }

        if (headers) {
            for (const [key, value] of Object.entries(headers)) {
                curlParts.push(`-H '${key}: ${value}'`);
            }
        }
        if (data) {
            if (method.toUpperCase() === 'GET') {
                const urlObj = new URL(url);
                for (const [key, value] of Object.entries(data)) {
                    urlObj.searchParams.append(key, value);
                }
                url = urlObj.toString();
            } else {
                const dataStr = typeof data === 'string' ? data : JSON.stringify(data);
                curlParts.push(`-d '${dataStr}'`);
            }
        }
        curlParts.push(`'${url}'`);
        return curlParts.join(' ');
    },

    openWindowWithFavicon() {
        // 获取favicon URL的函数
        function getFaviconUrl() {
            // 方法1: 查找现有的favicon链接
            const existingFavicon = document.querySelector('link[rel*="icon"]');
            if (existingFavicon) {
                return existingFavicon.href;
            }

            // 方法2: 使用默认的favicon路径
            return `${window.location.origin}/favicon.ico`;
        }

        // 打开新窗口
        var win = window.open("", "_blank");

        if (!win) {
            console.error('弹出窗口被阻止，请允许弹出窗口');
            return null;
        }

        // 设置新窗口的标题为当前页面的标题
        win.document.title = document.title;

        // 创建favicon链接
        const faviconLink = win.document.createElement('link');
        faviconLink.rel = 'icon';
        faviconLink.type = 'image/x-icon';
        faviconLink.href = getFaviconUrl();

        // 添加到新窗口的head
        win.document.head.appendChild(faviconLink);

        return win;
    }
};